package com.seednia.foundation.framework.service;

import com.seednia.foundation.framework.dto.AbstractRecord;
import com.seednia.foundation.framework.dto.QueryParams;
import com.seednia.foundation.framework.util.NumberUtils;

/**
 * Abstract class for all Web Service classes: REST & Soap services.
 * @author Young Suk Ahn
 *
 */
public abstract class AbstractWebService {

	public RequestContext createRequestContext(String accessToken){
		RequestContext retval = new RequestContext();
		// TODO: populate the request context accordingly (maybe use a factory)
		return retval;
	}
	
	protected void setCriteriaXid(AbstractRecord criteria, String xid)
	{
		if ( NumberUtils.isParsableToLong(xid) ) {
			criteria.setSid(Long.parseLong(xid));
		} else {
			criteria.setUuid(xid);
		}
	}
	
	/**
	 * Returns a default QueryParams if query para is null
	 * @param queryParams
	 * @return
	 */
	protected QueryParams obtainQueryParam(QueryParams queryParams)
	{
		if (queryParams == null)
			queryParams = new QueryParams(0, 20);
		return queryParams;
	}
}
